<?php
define('BASE_DIR', dirname(__FILE__)."/..");

require BASE_DIR.'/include/define.inc.php';
require BASE_DIR.'/include/setting.inc.php';

require BASE_DIR.'/ajax/Epic.php';

//Epic_Loader_Autoloader::getInstance();
function __autoload($class) {
	$path = str_replace('_', '/', $class);
	$file = $path . ".php";
	include $file;
	if (!class_exists($class, false) && !interface_exists($class, false)) {
		require 'Epic/Loader/Exception.php';
		throw new Epic_Loader_Exception('The requested class or interface: ' . $class . ' was not found.');
	}
}

// for deleter journal  from admin/journal/list
if (isset($_POST['sendValueTopic'])==true || isset($_POST['sendValueTo'])==true|| isset($_POST['sendValueFrom'])==true){
	$where = "";	
	if (isset($_POST['sendValueTopic'])) {
		$where  = "tp.id_topic IN (".implode(',', $_POST['sendValueTopic']).")";
	}
	if (isset($_POST['sendValueTo'])==true|| isset($_POST['sendValueFrom'])==true) {
		if ($_POST['sendValueFrom']!=0) {
			if ($where!="") $where .= "AND";
			$where .= " `year` >= '".$_POST['sendValueFrom']."'";
		}
		if ($_POST['sendValueTo']!=0) {
			if ($where!="")
				$where .= "AND";
			$where .= " `year` <= '".$_POST['sendValueTo']."'";
		}
	} 
	$query = "SELECT m.name,m.id_journal FROM journal as m
			LEFT JOIN pager as p ON (m.id_journal=p.id_journal)
			LEFT JOIN topic_pager as tp ON (p.id_pager=tp.id_pager)
			WHERE ".$where."
			GROUP BY m.id_journal";
	$rs = Epic::getAdapter()->query($query)
  				  			 ->fetchAll();
  	$dis = "";
  	foreach ($rs as $value) {
  		$dis.= '
  			<div class="detail_rs">
				<div class="reveal-content-title-full">
					<h3 class="journals-content-title">
						<a href="http://localhost/topicscientific/journal/article/listPager?id_journal='.$value['id_journal'].'">'.$value['name'].'</a>
					</h3>
					<p class="smFont">            				
							<span class="detailTitle">Publish Years: </span> 2013 
							<span class="pushLeft20">
								<a href="#">
								Most Recent Issue
								</a>
							</span>
					</p>
				</div>
				<div class="ClearFix"></div>
			</div>
  		';
  	}
	echo json_encode (array ('rs'=>$dis));
}
